﻿@page "/range-selector/logarithmic"
@using Syncfusion.Blazor.Charts
@using Syncfusion.Blazor
@inject NavigationManager NavigationManager
@inherits SampleBaseComponent;

<SampleDescription>
    <p>This sample demonstrates the rendering of logarithmic axis in the range navigator.</p>
</SampleDescription>
<ActionDescription>
    <p>Logarithmic axis uses logarithmic scale and it is very useful in visualizing when the data has values with both lower order of magnitude (eg: 10^-6) and higher order of magnitude (eg: 10^6). To render Logarithmic axis, set <code>ValueType</code> to <code>Logarithmic</code>. Tooltip is enabled in this example, to see the tooltip in action, while the selected range is changed.</p>
</ActionDescription>

@if (LogarithmicData == null)
{
    <div class="stockchartloader"></div>
}
else
{
    <div class="control-section" align="center">
        <h4 align="center" style="font-family: Segoe UI;font-weight: 500; font-style:normal; font-size:15px;">Inflation vs Goods Consumers</h4>
        <div>
            <SfRangeNavigator @bind-Value="@Value" ValueType="Syncfusion.Blazor.Charts.RangeValueType.Logarithmic" LabelIntersectAction="RangeLabelIntersectAction.None" LabelPosition="AxisPosition.Outside" Interval="2">
                <RangeNavigatorEvents Loaded="BeforeRender" Changed="onRangeChanged"></RangeNavigatorEvents>
                <RangeNavigatorRangeTooltipSettings Enable="true"></RangeNavigatorRangeTooltipSettings>
                <RangeNavigatorSeriesCollection>
                    <RangeNavigatorSeries Fill="@FillColor" DataSource="@LogarithmicData" Width="2" XName="x" Type="RangeNavigatorType.StepLine" YName="y">
                    </RangeNavigatorSeries>
                </RangeNavigatorSeriesCollection>
            </SfRangeNavigator>
        </div>
        <div>
            <SfChart>
                <ChartArea><ChartAreaBorder Width="0" Color="transparent"></ChartAreaBorder></ChartArea>
                <ChartPrimaryXAxis Interval="1" ValueType="Syncfusion.Blazor.Charts.ValueType.Logarithmic" EdgeLabelPlacement="EdgeLabelPlacement.Shift" Title="Numers of Goods Consumers" ZoomFactor="@ZF" ZoomPosition="@ZP">
                    <ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
                </ChartPrimaryXAxis>
                <ChartPrimaryYAxis Minimum="0" Maximum="600" Interval="100" LabelFormat="{value}%" Title="Inflation">
                    <ChartAxisMajorTickLines Width="0"></ChartAxisMajorTickLines>
                    <ChartAxisLineStyle Width="0"></ChartAxisLineStyle>
                </ChartPrimaryYAxis>
                <ChartSeriesCollection>
                    <ChartSeries Fill="@FillColor" DataSource="@LogarithmicData" XName="x" YName="y" Width="2" Type="ChartSeriesType.StepArea">
                        <ChartSeriesAnimation Enable="false"></ChartSeriesAnimation>
                        <ChartMarker Visible="true"></ChartMarker>
                    </ChartSeries>
                </ChartSeriesCollection>
                <ChartTooltipSettings Enable="false" Shared="false"></ChartTooltipSettings>
                <ChartLegendSettings Visible="false"></ChartLegendSettings>
            </SfChart>
        </div>
    </div>
}
@code{
    double ZF = 1;
    double ZP = 0;
    object Value = new object[] { 4, 6 };
    List<RangeData> LogarithmicData;
    string FillColor;
    string valueUrl = "url";
    private Theme theme { get; set; }
    protected override async Task OnInitializedAsync()
    {
        await Task.Run(() =>
        {
            List<RangeData> data = new List<RangeData>();
            int max = 100;
            Random rand = new Random();
            double Value;
            for (int i = 0; i < max; i++)
            {
                Value = rand.Next(1, 10);
                data.Add(new RangeData { x = Math.Pow(10, i * 0.1), y = Math.Floor(Value * (80 - 30 + 1)) + 30 });
            }
            LogarithmicData = data;
        });

        CurrentUri = NavigationManager.Uri;
        if (CurrentUri.IndexOf("material") > -1)
        {

            FillColor = String.Concat(valueUrl, "(#material-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("fabric") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#fabric-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("bootstrap4") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#bootstrap4-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("bootstrap") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#bootstrap-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("highcontrast") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#highcontrast-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("tailwind") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#tailwind-gradient-chart)");
        }
        else
        {
            FillColor = String.Concat(valueUrl, "(#bootstrap4-gradient-chart)");
        }
    }

    public class RangeData
    {
        public Double x { get; set; }
        public Double y { get; set; }
    }
    public void onRangeChanged(ChangedEventArgs args)
    {
        ZF = args.ZoomFactor;
        ZP = args.ZoomPosition;
        StateHasChanged();
    }

    string CurrentUri;
    void BeforeRender(RangeLoadedEventArgs Args)
    {
        CurrentUri = NavigationManager.Uri;
        if (CurrentUri.IndexOf("material") > -1)
        {
            Args.Theme = Theme.Material;
        }
        else if (CurrentUri.IndexOf("fabric") > -1)
        {
            Args.Theme = Theme.Fabric;
        }
        else if (CurrentUri.IndexOf("bootstrap") > -1)
        {
            Args.Theme = Theme.Bootstrap;
        }
        else if (CurrentUri.IndexOf("highcontrast") > -1)
        {
            Args.Theme = Theme.HighContrast;
        }
        else if (CurrentUri.IndexOf("tailwind") > -1)
        {
            Args.Theme = Theme.Tailwind;
        }
        else
        {
            Args.Theme = Theme.Bootstrap4;
        }
    }

    protected override void OnInitialized()
    {
        CurrentUri = NavigationManager.Uri;
        if (CurrentUri.IndexOf("material") > -1)
        {
            theme = Theme.Material;
        }
        else if (CurrentUri.IndexOf("fabric") > -1)
        {
            theme = Theme.Fabric;
        }
        else if (CurrentUri.IndexOf("bootstrap4") > -1)
        {
            theme = Theme.Bootstrap4;
        }
        else if (CurrentUri.IndexOf("bootstrap") > -1)
        {
            theme = Theme.Bootstrap;
        }
        else if (CurrentUri.IndexOf("highcontrast") > -1)
        {
            theme = Theme.HighContrast;
        }
        else if (CurrentUri.IndexOf("tailwind") > -1)
        {
            theme = Theme.Tailwind;
        }
        else
        {
            theme = Theme.Bootstrap4;
        }
    }

}
<style>
    #control-container {
        padding: 0px !important;
    }

    #material-gradient-chart stop {
        stop-color: #00bdae;
    }

    #fabric-gradient-chart stop {
        stop-color: #4472c4;
    }

    #bootstrap-gradient-chart stop {
        stop-color: #a16ee5;
    }

    #bootstrap4-gradient-chart stop {
        stop-color: #a16ee5;
    }

    #highcontrast-gradient-chart stop {
        stop-color: #79ECE4;
    }

    .chart-gradient stop[offset="0"] {
        stop-opacity: 0.9;
    }

    .chart-gradient stop[offset="1"] {
        stop-opacity: 0.3;
    }

    #tailwind-gradient-chart stop {
        stop-color: #4F46E5;
    }
</style>
<svg style="height: 0">
    <defs>
        <linearGradient id="material-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="fabric-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="bootstrap-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="bootstrap4-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="highcontrast-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="tailwind-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
    </defs>
</svg>